package Professor;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ProfessorDAO {

	private final String DRV = "oracle.jdbc.driver.OracleDriver";
	private final String URL = "jdbc:oracle:thin:realdance/realdance@112.216.253.125:1521:xe";
	private final String insertSQL = "insert into PROFESSOR_VO values"
			+"(exam.nextval,?,?,?,?,?,?,?,?)";
	private final String selectSQL = "select * from PROFESSOR_VO order by PROF_NO desc"; 	
	private final String updateSQL = "PROFESSOR_VO set PROF_NO=?, USER_PW=?, PROF_NAME=?, PROF_TEL=?, PROF_ADDR=?, PROF_OFFICE=?, DEPT_NO=?, SUB_NO=? sysdate wheree PROF_NO=? ";
	
	
	protected Connection openDatabase(){

		try{
			Class.forName(DRV);
			
		return DriverManager.getConnection(URL);				
		}catch(Exception e){
		e.printStackTrace();	
		}
		
		return null;
		
	}
	protected void closeDatabase(Connection c, PreparedStatement p, ResultSet r){
		
		if(r != null)try{r.close(); r = null;}	catch(Exception e){}
		if(p != null)try{p.close(); p = null;}	catch(Exception e){}
		if(c != null)try{c.close(); c = null;}	catch(Exception e){}
	}
	public boolean insertProf(ProfessorVO pf){
		boolean result = false;
		Connection conn = null;
		PreparedStatement pstmt = null;
	
		try{
			conn = openDatabase();
			pstmt = conn.prepareStatement(insertSQL);
			pstmt.setString(1, pf.getPROF_NO());
			pstmt.setString(2, pf.getUSER_PW());
			pstmt.setString(3, pf.getPROF_NAME());
			pstmt.setString(4, pf.getPROF_TEL());
			pstmt.setString(5, pf.getPROF_ADDR());
			pstmt.setString(6, pf.getPROF_OFFICE());
			pstmt.setString(7, pf.getDEPT_NO());
			pstmt.setString(8, pf.getSUB_NO());
			pstmt.executeUpdate();
			result = true;
			
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			closeDatabase(conn, pstmt, null);
		}
		return result;
		}
}	


